import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.http.*;

public class LoginChk extends HttpServlet
{
    private HttpServletRequest request=null;
	private HttpServletResponse response=null;

	 public void doPost(HttpServletRequest request, HttpServletResponse response)
    {
		 this.request=request;
		 this.response=response;
           processRequest(request,response);
    }
  public void doGet(HttpServletRequest request, HttpServletResponse response)
  {
    	  this.request=request;
	      this.response=response;
	      processRequest(request,response);
  }
   public void processRequest(HttpServletRequest request, HttpServletResponse response)
  {
    try
     {      
       
       String userId=request.getParameter("txtuser");

	   if(isAuthenticate(userId))
		 {
		    SetSession("userSession",userId);
			response.sendRedirect("Inbox.html");
		 }
		else
			response.sendRedirect("LoginPage.html");
       	
     }catch(Exception e)
      {
         //out.println(e.toString());
      }
  }

	private boolean isAuthenticate(String uid)
	{
		if(uid.equals("jabu"))
			return true;
		else
			return false;
	}
private void SetSession(String sessionName,String sessionValue)
	{
       HttpSession session = request.getSession(true);
	   //session.setAttribute("SessionName", "SessionValue");
	   session.setAttribute(sessionName, sessionValue);
	}
}
